﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JavaScript遍历table的行和列</title>
    <script type="text/javascript">
        // 遍历表格的每行每列
        function viewCell(){
            let count = 1;
            for(let i = 0;i< document.all.tbl.rows.length;i++){
                for(let j = 0;j< document.all.tbl.rows(i).cells.length;j++){
                    document.all.tbl.rows(i).cells(j).innerText = count;
                    count++;
                }
            }
        }
    </script>
    
</head>
<body onload="viewCell()">
<TABLE id="tbl" border=1 width="200">
    <TR><TH>&nbsp;</TH><TH>&nbsp;</TH><TH>&nbsp;</TH><TH>&nbsp;</TH></TR>
    <TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>
    <TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>
</TABLE>
</body>
</html>